package com.web.listener;

import javax.servlet.ServletRequest;
import javax.servlet.ServletRequestAttributeEvent;
import javax.servlet.ServletRequestAttributeListener;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;

//event 事件  
// 1.事件的名称(内容) 
// 2.事件触发人(程序) 
// 3.事件处理(人)程序 负责监听事件的对象

public class MyRequestListener 
	implements ServletRequestListener,ServletRequestAttributeListener {
	@Override
	public void requestDestroyed(ServletRequestEvent event) {
		ServletRequest request = event.getServletRequest();
		System.out.println("销毁request对象:"+request);
	}

	@Override
	public void requestInitialized(ServletRequestEvent event) {
		ServletRequest request = event.getServletRequest();
		System.out.println("初始化request对象:"+request);
	}

	//request.setAttribute("a",123);
	@Override
	public void attributeAdded(ServletRequestAttributeEvent event) {
		System.out.println("===1.向request存储数据....");
		String name  = event.getName();
		Object value = event.getValue();
		System.out.println(name+"----->" + value);
	}

	@Override
	public void attributeRemoved(ServletRequestAttributeEvent event) {
		System.out.println("===2.从request移除数据...");
		String name = event.getName();
		Object value = event.getValue();
		System.out.println(name+"---->" + value);
	}

	@Override
	public void attributeReplaced(ServletRequestAttributeEvent event) {
		System.out.println("===3.向request替换数据...");
		String name = event.getName();
		Object value = event.getValue();
		System.out.println(name+"---->" + value);
	}
	

}
